package in.equilibr.ingredients.service;

import in.equilibr.ingredients.dao.ActivityDAO;
import in.equilibr.ingredients.model.Activity;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import com.google.gson.Gson;

// json dependency

@Service
public class ActivityService {
	private static final Logger logger = LoggerFactory
			.getLogger(ActivityService.class);

	@Autowired
	private ActivityDAO activityDAO;

	public ModelAndView buildListView(List<Activity> activities) {
		// it's a new Object for the function/field "Add new activity"
		Activity newActivity = new Activity();

		ModelAndView mv = new ModelAndView("activity");
		mv.addObject("newActivity", newActivity);
		mv.addObject("message", "There are " + activities.size()
				+ " activities read.");
		mv.addObject("activities", activities);
		mv.addObject("activityDAO", activityDAO);

		return mv;
	}

	public String convertJson(List<String> values) {
		Gson gson = new Gson();
		logger.info("JSON-Object is " + gson.toJson(values));
		return gson.toJson(values);
	}
}